import { SquareGroup } from "./SquareGroup";
import { IPoint } from "./Type";
import { getRandom } from "./util";

// O
export class SquareShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: 0, y: 0 },
        { x: 1, y: 0 },
        { x: 0, y: 1 },
        { x: 1, y: 1 },
      ],
      centerPoint,
      color
    );
  }

  public rotate(): void {}
}

// I
class LineShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: 0, y: -1 },
        { x: 0, y: 0 },
        { x: 0, y: 1 },
        { x: 0, y: 2 },
      ],
      centerPoint,
      color
    );
  }

  public rotate() {
    super.rotate();
    this._isClock = !this._isClock;
  }
}

// S
class SShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: 0, y: 0 },
        { x: 1, y: 0 },
        { x: 0, y: 1 },
        { x: -1, y: 1 },
      ],
      centerPoint,
      color
    );
  }
}

// Z
class ZShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: -1, y: 0 },
        { x: 0, y: 0 },
        { x: 0, y: 1 },
        { x: 1, y: 1 },
      ],
      centerPoint,
      color
    );
  }
}

// L
class LShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: -2, y: 0 },
        { x: -1, y: 0 },
        { x: 0, y: 0 },
        { x: 0, y: -1 },
      ],
      centerPoint,
      color
    );
  }
}

class JShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: 0, y: 0 },
        { x: -1, y: 0 },
        { x: 0, y: -2 },
        { x: 0, y: -1 },
      ],
      centerPoint,
      color
    );
  }
}

// T
class TShape extends SquareGroup {
  constructor(centerPoint: IPoint, color: string) {
    super(
      [
        { x: 0, y: 0 },
        { x: -1, y: 0 },
        { x: 1, y: 0 },
        { x: 0, y: 1 },
      ],
      centerPoint,
      color
    );
  }
}

export const shapes = [SquareShape, LineShape, SShape, ZShape, LShape, JShape, TShape];
export const colors = ["red", "green", "blue", "orange"];

/**
 * 创建一个随机方块
 * @param centerPoint
 */
export function createTetris(centerPoint: IPoint) {
  return new shapes[getRandom(0, shapes.length)](centerPoint, colors[getRandom(0, colors.length)]);
}
